<template>
    <div class="form-box">
        <el-form ref="form" :model="form" label-position="left" label-width="200px" >
             
            <!-- <el-form-item label="计划投资额(万元)">
                <el-input type="number"  v-model="form.planInvestment"  ></el-input>
            </el-form-item>
             <el-form-item label="截至上一年完成投资额(万元)" >
                <el-input type="number"  v-model="form.lastyearInvestment" ></el-input>
            </el-form-item>
            <el-form-item label="计划建设内容">
                <el-input type="textarea"  row="4" v-model="form.consContent" ></el-input>
            </el-form-item>
            <el-form-item label="是否为重点项目">
                <el-select v-model="form.isImportant">
                    <el-option v-for="item in isImportants" :key="item.value" :label="item.name" :value="item.value"></el-option> 
                </el-select>
            </el-form-item>
            <el-form-item label="时间年" >
                <el-date-picker  type="year"  v-model="dateYear" placeholder="选择日期" class="dateWidth" value-format="yyyy">
                </el-date-picker>
            </el-form-item>
            <el-row :gutter="20">
                <div class="commit-btn">
                    <el-button type="primary"  v-on:click="submit()">提交</el-button>
                </div>
            </el-row> -->
            <el-form-item label="本年估算投资">
                <el-input type="number"  v-model="form.planInvestment"  ></el-input>
            </el-form-item>
             <el-form-item label="至上年底累计投资（万元）" >
                <el-input type="number"  v-model="form.lastyearInvestment" ></el-input>
            </el-form-item>
            <el-form-item label="建设规模和内容">
                <el-input type="textarea"  row="4" v-model="form.consContent" ></el-input>
            </el-form-item>
            <el-form-item label="是否市领导联点项目（调度表）">
                <el-select v-model="form.isImportant">
                    <el-option v-for="item in isImportants" :key="item.value" :label="item.name" :value="item.value"></el-option> 
                </el-select>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
    import date_formate from "../tool/Global/dateutil.js";
    import {queryProYearScheduleByPkid,addProYearSchedule,updateProYearSchedule} from "../tool/Global/app-mgr.js";
    export default {
        props: ['projectId','progressId','userInfo'],
        data:function(){
            return{
                form:{
                    pkid:"",
                    projectID:"",
                    planInvestment:"",
                    consContent:"",
                    dateYear:"",
                    createPersonID:"",
                    createPerson:"",
                    lastyearInvestment:"",
                    isImportant:"",               
                },
                dateYear:"",  
                isImportants:[{
                        name:'是',
                        value:1
                    },{
                        name:'否',
                        value:0
                    }]                        
            }
        },
        mounted:function(){
            let ref = this;
            ref.form.createPersonID = ref.userInfo.createPersonID;
            ref.form.createPerson = ref.userInfo.createPerson;
            ref.form.projectID = ref.projectId;
            this.$nextTick(function () {
                if(ref.progressId){
                    ref.form.pkid = ref.progressId;
                    queryProYearScheduleByPkid(ref.progressId).then(function(result){
                        if(result.data.success){
                            let data = result.data.data;
                            for(var key in ref.form){
                                ref.form[key] = data[key]!=null?data[key]:'';

                            }
                            if(data.isImportant==0){
                                ref.form.isImportant = 0;
                            }
                            ref.dateYear = data.dateYear?date_formate.format(new Date(data.dateYear),"yyyy"):'';
                        }
                    })
                }
            })
        },
        methods:{
            submit(){
                var data = {                      
                    proYearScheduleStr:JSON.stringify(this.form),
                    dateYear:this.dateYear                       
                }
                let ref = this;
                let params = new URLSearchParams()
                for (var key in data) {
                    params.append(key, data[key])
                }
                if(this.progressId){
                   
                    updateProYearSchedule(params).then(function(result){
                        if(result.data.success){
                            ref.$message({message:"更新成功",type:"success"})
                            ref.$emit("listenClose");
                        }else{
                            ref.$message.error(result.data.message)
                        }
                    })
                }else{
                    addProYearSchedule(params).then(function(result){
                        if(result.data.success){
                            ref.$message({message:"添加成功",type:"success"})
                            ref.$emit("listenClose");
                        }else{
                            ref.$message.error(result.data.message)
                        }
                    })
                } 
            },
        }
    }
</script>
<style scoped>
    .commit-btn{
        text-align: center;
    }
</style>


